<template>
  <el-card class="box-card" style="width: 1180px">   
    <div slot="header" class="clearfix">
      <el-form :inline="true" :model="query">
        <el-form-item>
          <el-row>
          <el-col :span="20">
                    <el-button type="success" @click="exportExcel">导出数据</el-button>
           </el-col>
           <el-col :span="4">
               <el-upload
                   class="clearfix"
                   action="http://localhost:8888/banks/importExcel"
                   name="file"
                   :on-progress="onExcelProgress"
                   :on-success="handleExcelSuccess"                   
                   accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
                   multiple
                   :limit="1"
                   >
                <el-button  type="primary">数据导入</el-button>
                <el-button  type="success" @click="tu()">散点聚合图</el-button>
               </el-upload>
         </el-col>
     </el-row>   
        </el-form-item>
      </el-form>
    </div>      
    <el-table :data="pipeList" border style="width: 100%">
        <el-table-column prop="pipelineId" label="流水编号" >
</el-table-column>
      <el-table-column prop="pipelineBy1" label="银行账号" >
      </el-table-column>
      <el-table-column prop="pipelineType" label="流水类别">
      </el-table-column>
        <el-table-column prop="pipelineInorout" label="类型">
      </el-table-column>
      <el-table-column prop="pipelineBy2" label="金额">
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="query.currentPage"
      :page-sizes="pageInfo.pageSizes"
      :page-size="query.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageInfo.total">
    </el-pagination>
  </el-card>
</template>

<script>
export default {
  data() {
    return {
        pipeList:[],
        pageInfo: {       
        pageSizes: [5, 20, 30, 50, 100],        
        total: 1,
      },
      query:{
        currentPage: 1,
        pageSize: 5,
        realName:"",
        dateRange:[]
      },
      addForm:{},
      updateForm:{},
    };
  },
  methods: {
    tu(){
      this.$router.push("/moddle");
    },
    handleExcelSuccess(res,result) {
                this.$message.success("导入成功");
                if (result.response.success) {
                    this.loadPis();
                }
            },
            // 上传中
            onExcelProgress(){

            },
    exportExcel() {      
      this.$axios
        .post("banks/exportExcel", this.query,{responseType: 'blob'})
        .then((res) => {
          let fileName = res.headers["content-disposition"].split("=")[1];//得到后端生成的文件名          
          let url = window.URL.createObjectURL(new Blob([res.data]));
          let dom = document.createElement("a");
          dom.style.display = "none";
          dom.href = url;
          dom.setAttribute("download", fileName); //指定下载后的文件名，防跳转
          document.body.appendChild(dom);
          dom.click();
          // 释放内存
          dom.parentNode.removeChild(dom)
          window.URL.revokeObjectURL(dom.href);
        })
        .catch(function (error) {
          console.log(error);
        });
    },
    handleSizeChange(size) {      
      this.query.pageSize = size;
      this.loadPis();
    },
    //当页数改变时
    handleCurrentChange(currentPage) {     
      this.query.currentPage = currentPage;
      this.loadPis();
    },
    loadPis(){
        this.$axios.post("/banks/pis",this.query)
        .then(res=>{
            this.pipeList=res.data.data.list;
            this.pageInfo.total=res.data.data.total;
        })
    },
  },
  mounted(){
    this.loadPis();
  }
};
</script>